// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import ComponentBase from "../../BASE/ComponentBase";
import state from "../../game/time/state";
import GeZiManager from "../../Manager/GeZiManager";
import { Message } from "../../Message/Message";



const {ccclass, property} = cc._decorator;

@ccclass
export default class GeZi extends ComponentBase {

    @property
   ZB:number=0;
   
   @property
   X:number=0;
 
   @property
  Y:number=0;
  @property
DiXing:String="grass";
  @property(cc.Node)
    standBY: cc.Node[] = null;


   
puper(){this.node.color=cc.color(255,48,255);this.node.getComponent(cc.Button).enabled=false;this.node.opacity=155;}
blue(){this.node.color=cc.color(48,48,255);this.node.getComponent(cc.Button).enabled=false;this.node.opacity=155;}
red(){this.node.color=cc.color(255,12,12),this.node.getComponent(cc.Button).enabled=false;this.node.opacity=155;GeZiManager.kxg+=1}
green(){this.node.color=cc.color(54,231,158);this.node.getComponent(cc.Button).enabled=true;this.node.opacity=155;}
black(){
    this.node.color=cc.color(0,0,0),this.node.getComponent(cc.Button).enabled=false;this.node.opacity=155;
GeZiManager.kxg+=1
}
null(){this.node.getComponent(cc.Button).enabled=false;this.node.opacity=0;}



       


    
 onLoad(){
    GeZiManager.YuanGong.push(this)



}










   /* start () {

      let a:number[]=[5,6,7]
     if(a.includes(this.X)){this.red();}

this.node.zIndex=8-(this.Y+0.5);
}*/


 getFar(dis:number){
let x;
let y;
    
        if(GeZiManager.GeZi%8==0){x=8}else {x=GeZiManager.GeZi%8;}
    y=Math.ceil(GeZiManager.GeZi/8);
    
if(Math.abs(x-this.X)+Math.abs(y-this.Y)>=dis){ this.red();}
else{this.green();}

}



getFarIN(dis:number){
    let x;
    let y;
        
            if(GeZiManager.GeZi%8==0){x=8}else {x=GeZiManager.GeZi%8;}
        y=Math.ceil(GeZiManager.GeZi/8);
        
    if(Math.abs(x-this.X)+Math.abs(y-this.Y)>=dis){ }
    else{GeZiManager.GeZis.push(this.ZB )}
    
    }

out(){
GeZiManager.shanchuALL(GeZiManager.GeZis,this.ZB)


}








    ReceiveMessage(message:Message){

        switch(message.Content){
   
 case "redBan":
    let XS:number[]=[2,3,4,5]
    let YS:number[]=[];

    
        for(let ZB of GeZiManager.blue ){
           
           let x 
           let y
            if(ZB%8==0){x=8}else {x=ZB%8;}
            XS.push(x);
           
            y=Math.floor(ZB/8)+1;
            YS.push(y);

            if (GeZiManager.by[4]==2) {
               XS.push(6)
            }
            if (GeZiManager.by[3]==1) {
                XS.push(5)
             }
//XS=GeZiManager.mArr1Arr2(XS,GeZiManager.LSban)

if(XS.includes(this.X)){
    this.red();
}

if(YS.includes(this.Y)){
    this.red();
}


}

if(GeZiManager.red.includes(this.ZB)){
    this.black();
}
GeZiManager.Gtree();
break;
















case "blueBan":
     XS=[4,5,6,7]
     YS=[];
   
     if (GeZiManager.by[1]==2) {
        XS.push(3)
     }
     if (GeZiManager.by[2]==1) {
         XS.push(4)
      }
        for(let ZB of GeZiManager.red ){
           
           let x
            if(ZB%8==0){x=8}else {x=ZB%8;}
            XS.push(x);
            let y
            y=Math.floor(ZB/8)+1;
            YS.push(y);
          
 //XS=GeZiManager.mArr1Arr2(XS,GeZiManager.LSban)
  
if(XS.includes(this.X)){
    

    this.red();
   
}
if(YS.includes(this.Y)){
    this.red();
}



}
if(GeZiManager.blue.includes(this.ZB)){

    this.black();}
GeZiManager.Gtree();


    break;

















default:
if(message.Command[0]==65){
switch(message.Content){
    case -1:this.red();
    break ;   
    case 0:this.null();
break ;   
case 1:this.green();
break ;
case 2:this.blue();
break ;

}
}
if(message.Command.includes(this.ZB)){
    switch(message.Content){
        case -1:this.red();
        break ;   
        case 0:this.null();
    break ;   
    case 1:this.green();
    break ;   
    case 2:this.blue();
    break ;
case 5: this.black();
break;
}




}






}







}














  








}
   

